import Foundation
import SwiftData

@Model
final class Folder {
    var id: UUID
    var name: String
    var createdAt: Date
    var modifiedAt: Date
    @Relationship(deleteRule: .cascade) var subfolders: [Folder]
    @Relationship(deleteRule: .cascade) var notes: [Note]
    @Relationship(inverse: \Folder.subfolders) var parent: Folder?
    var isExpanded: Bool?
    var isDefault: Bool
    
    init(name: String, parent: Folder? = nil, isDefault: Bool = false) {
        self.id = UUID()
        self.name = name
        self.createdAt = Date()
        self.modifiedAt = Date()
        self.subfolders = []
        self.notes = []
        self.parent = parent
        self.isExpanded = true
        self.isDefault = isDefault
    }
}

@Model
final class Note {
    var id: UUID
    var title: String
    var content: String
    var createdAt: Date
    var modifiedAt: Date
    var isMarkdown: Bool
    @Relationship(inverse: \Folder.notes) var folder: Folder?
    
    init(title: String, content: String = "", isMarkdown: Bool = false) {
        self.id = UUID()
        self.title = title
        self.content = content
        self.createdAt = Date()
        self.modifiedAt = Date()
        self.isMarkdown = isMarkdown
    }
} 